package org.blogwu.learn.multithread.chapter3.demo1;

import java.util.concurrent.locks.ReentrantLock;

public class Main3 {

    public static ReentrantLock lock = new ReentrantLock();
    public static int it = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {

            try {
                lock.lock();
                System.out.println("Sss");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                int i = 1 / 0;

                lock.unlock();
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }


        });

        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("尝试获取锁");
            lock.lock();


            System.out.println("取到锁了");
            lock.unlock();

        });

        t1.start();
        t2.start();
    }
}
